<?php
 
defined("_VALID_ACCESS") || die('Direct access forbidden');
 
class SCTV_AreaCommon extends ModuleCommon {
 
    public static function menu() {
    	return array(__('SCTV') => array(
    		'__submenu__' => 1, __('List') => array(
    			'__submenu__' => 2, 
        		__('Area') => array(),
			)
		));
    }

    /**
     * @param $manager_id
     * @return array
     */
    public static function get_area_by_id_manager($manager_id) {
        $area = DB::GetAssoc('
            SELECT id, f_name
            FROM sctv_area_data_1
            WHERE active = 1 and sctv_area_data_1.f_manager = %d
        ',
            array($manager_id)
        );
        $result = array();
        $i = 0;
        foreach ($area as $id => $name) {
            $result[$i]['id'] = $id;
            $result[$i]['name'] = $name;
            $i++;
        }
        return $result;
    }

	public static function get_area($i_am_admin, $manager_id)
	{		
		$area = DB::GetAssoc('
			SELECT id, f_name 
			FROM sctv_area_data_1 
			where active = 1 and (true = %b or sctv_area_data_1.f_manager = %d)
		',
		array($i_am_admin, $manager_id));
		foreach ($area as $k=>$u)
			$area[$k] = $u;
			
		asort($area);
		$area = array(''=>__('All'))+$area;
		return $area;
	}
    public static function get_area_is_not_manager($i_am_admin, $manager_id)
    {
        $area = DB::GetAssoc('
			SELECT id, f_name
			FROM sctv_area_data_1
			where active = 1 and (true = %b or sctv_area_data_1.f_manager != %d)
		',
            array($i_am_admin, $manager_id));

        foreach ($area as $k=>$u)
            $area[$k] = $u;

        asort($area);
        $area = array(''=>__('All'))+$area;
        return $area;
    }
}
 
?>